// JScript source code for CodeTextArea control
function CodeTextArea_Focus(objElement, objEvent, strGuid)
{
    objElement.style.backgroundColor = "yellow";
}

function CodeTextArea_Blur(objElement, objEvent, strGuid)
{
    objElement.style.backgroundColor = "white";
}

function Web_CharOnKeyPress(objEvent)
{
    return String.fromCharCode(objEvent.charCode || objEvent.keyCode);
}

function CodeTextArea_KeyPress(objElement, objEvent, strGuid)
{
    var strValue = Web_CharOnKeyPress(objEvent);

//    objElement.innerHTML += strValue;
    
    var objNode = Data_GetNode(strGuid);
    
    var oldText = Xml_GetAttribute(objNode,"Attr.Text")
    
    var newText = oldText + strValue;
    
	// If data has changed
	if(newText!=oldText)
	{
		// Update data behind
		Data_SetAttribute(strGuid,"Attr.Text",newText);
	
		// Create event
		var objCodeChangeEvent = Events_CreateEvent(strGuid, "CodeChanged", null, true);
		
		// Set event text attribute
		Events_SetEventAttribute(objCodeChangeEvent, "Attr.Text", newText);
	    Events_ClearScheduleRaiseEvents();
	    Events_ScheduleRaiseEvents(1000);
	}
}

function CodeTextArea_KeyDown(objElement, objEvent, strGuid)
{
    // Get the pressed key
	var intKeyCode = Web_GetEventKeyCode(objEvent)*1;
    
    if (intKeyCode==8)
    {
        objElement.innerHTML = objElement.innerHTML.substr(0, objElement.innerHTML.lenght-1);
    }
    if (intKeyCode==13)
    {
        objElement.innerHTML += "\n";
    }
    else
    {
        if(intKeyCode>31)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
